from selenium import webdriver
from selenium.webdriver.common.by import By
import time,pytest
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as Ec
from selenium.webdriver.common.keys import Keys
@pytest.fixture()
def driver():
    driver=webdriver.Edge()
    driver.get('https://www.jiuxian.com/')
    driver.maximize_window()
    yield driver
    driver.quit()
def test_jiuxian(driver):
    # 断言请登录
    dy4=driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]').text
    print(dy4)
    time.sleep(2)
    # 点击请登录
    driver.find_element(By.CLASS_NAME,'headerLogin').click()
    # 强制等待
    time.sleep(2)
    # 断言账号登录
    dy1=driver.find_element(By.XPATH,'//*[@id="loginform"]/div/div/div/div/div[1]/div[1]/a[1]').text
    print(dy1)
    time.sleep(2)
    # 输入用户名
    driver.find_element(By.ID,'userName').send_keys('15336710135')
    # 输入密码
    driver.find_element(By.XPATH,'//*[@id="password"]').send_keys('002816Hj')
    time.sleep(15)
    # # 回车
    # driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(Keys.ENTER)
    # # 多窗口切换
    # driver.switch_to.window(driver.window_handles[-1])
    # # 进入iframe框架
    # driver.switch_to.frame(driver.find_element(By.XPATH,'//*[@id="wd"]'))
    # # 退出iframe框架
    # driver.switch_to.default_content()
    # 点击登录
    driver.find_element(By.NAME,'bi_Usuallogin').click()
    # 隐式等待
    driver.implicitly_wait(5)
#     断言jxw434465443
    dy2=driver.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span').text
    print(dy2)
    time.sleep(2)
#   点击输入框 id="wd"，class="search-form"
    driver.find_element(By.XPATH,'//input[starts-with(@id,"wd")]').send_keys("茅台")
    time.sleep(2)
    # 断言搜索框中的内容
    dy3=driver.find_element(By.XPATH,'//*[@id="wd"]').text
    print(dy3)
    time.sleep(2)
    # 点击搜索按钮 class="search-btn"
    # 显示等待
    xianshi=WebDriverWait(driver,20,0.5).until(Ec.presence_of_element_located((By.XPATH,'/html/body/div[4]/div/div[2]/div[1]/form/input[2]')))
    xianshi.click()
    # 断言全部商品分类
    dy3=driver.find_element(By.XPATH,'/html/body/div[4]/div/div/h2').text
    print(dy3)
    time.sleep(2)